package de.bazinga.rotw.menu.objects;

import com.jme.math.Vector3f;
import com.jme.scene.Controller;
import com.jme.scene.shape.Box;

public class MovingBox extends Box {
	private static final long serialVersionUID = 1L;

	public MovingBox() {
		super("test",new Vector3f(0,0,0),new Vector3f(1,1,1));
		
		this.addController(new TestController(this));
	}
}


class TestController extends Controller {
	private static final long serialVersionUID = 1L;

	private MovingBox box;
	
	private boolean right = true;
	private boolean left = false;
	
	public TestController(MovingBox box) {
		this.box = box;
	}

	@Override
	public void update(float tpf) {
		if(box.getLocalTranslation().x < 3 && right) {
			box.setLocalTranslation(box.getLocalTranslation().x + 0.01f, 
					box.getLocalTranslation().y, 
					box.getLocalTranslation().z);
			if(box.getLocalTranslation().x >= 3) {
				right = !right;
				left = !left;
			}
		}else if(box.getLocalTranslation().x > -3 && left){
			box.setLocalTranslation(box.getLocalTranslation().x - 0.01f, 
					box.getLocalTranslation().y, 
					box.getLocalTranslation().z);
			
			if(box.getLocalTranslation().x <= -3) {
				right = !right;
				left = !left;
			}
		}
	}
}